package com.itheima.reggie.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//点餐端订单的表现层控制器
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //提交购物车
    @PostMapping("/submit")
    public ResultInfo submitOrder(@RequestBody Order order) {
        //调用service
        orderService.submitOrder(order);
        //返回
        return ResultInfo.success();
    }

    //查询历史订单
    @GetMapping("/userPage")
    public ResultInfo findOldOrder(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize) {
        //调用mapper
        Page<Order> page = orderService.findOldOrder(pageNum, pageSize);
        //返回
        return ResultInfo.success(page);
    }
}
